import { exit } from 'node:process'
import * as path from 'node:path'
import * as fs from 'node:fs'

export const only = (version, basepath = 'node_modules/uWebSockets.js/') => {
    const useful = `uws_${version}.node`
    if (!basepath.startsWith('/')) {
        basepath = path.join(process.cwd(), basepath)
    }
    if (!fs.existsSync(basepath)) {
        console.error(`uWs bin filter: ${basepath} not exists`)
        exit(1)
    }
    fs.readdirSync(basepath).forEach(file => {
        if (/^uws_(\w+)\.node$/.test(file) && file != useful) {
            console.info(`uWs bin delete: ${basepath}${file}`)
            fs.unlinkSync(path.join(basepath, file))
        }
    })
}
